

sort id year_bin
xtset id year_bin, yearly

* NB:  x = longitude, y = latitude
spset id, coord(cent_long cent_lat) coordsys(latlong, kilometers)


*** FISH CATCH VARIABLES ***

gen ln_dem_d_tot = ln(1+dem_d_tot)
gen ln_dem_hb_tot = ln(1+dem_hb_tot)
gen ln_pel_hb_tot = ln(1+pel_hb_tot)

gen dem_tot = dem_d_tot + dem_hb_tot
gen ln_dem_tot = ln(1+dem_tot)

gen catch_tot = dem_d_tot + dem_hb_tot + pel_hb_tot
gen ln_catch_tot = ln(1 + catch_tot)

bysort year_bin fao_area : egen meancatch = mean(catch_tot)
gen ln_meancatch = ln(1 + meancatch)

gen ln_diffcatch = ln_catch_tot - ln_meancatch

bysort year_bin fao_area : egen meandem = mean(dem_tot)
gen ln_diffdem = ln_dem_tot - ln(1 + meandem)

bysort year_bin fao_area : egen meanpel = mean(pel_hb_tot)
gen ln_diffpel = ln_pel_hb_tot - ln(1 + meanpel)

gen ln_iuu_tot = ln(1 + iuu_tot)

gen ln_npp_tot = ln(1 + npp_tot)


*** OTHER VARIABLE TRANSFORMATIONS ***

gen ln_pop = log(1 + pop)
label variable ln_pop "log(1 + Population) (2005, 2010)"

gen ln_ship_mean = log(1 + ship_mean)
label variable ln_ship_mean "log(1 + Shipping Mean) (2008, 2013)"

gen ln_nl_mean = log(1 + nl_mean)
label variable ln_nl_mean "log(1 + Nightlight Mean) (2005, 2010)"


*** GENERATE ADDITIONAL DUMMIES ***

gen country_eez = (countryname != "")
label variable country_eez "Dummy if Square Touches Land or EEZ"

gen land = (ocean==0&coast==0&all_ocean==0)
gen landed = (land==1|coast==1)

tab fao_area, gen(_fao_area)

tab year_bin, gen(y_)


*** STANDARDIZE VARIABLES ***

egen zfragile = std(fragile)
egen zlights = std(ln_nl_mean)
egen zevap = std(evap_min)
egen zpop = std(ln_pop)
egen zports = std(ports)
egen zships = std(ln_ship_mean)
egen zmilbase = std(milbase_total)
egen zdiffcatch = std(ln_diffcatch)
egen zdiffdem = std(ln_diffdem)
egen zdiffpel = std(ln_diffpel)
egen ziuu = std(ln_iuu_tot)
egen znpp = std(ln_npp_tot)


*** LABEL SOMALIA-YEMEN EEZs ***

split countryname, p(";")

gen c_SOM= 0
gen c_YEM= 0

forvalues i = 1(1)14 {
	replace c_SOM= 1 if strpos(countryname`i',"Somalia")
	replace c_YEM= 1 if strpos(countryname`i',"Yemen, Rep.")
}

drop countryname1-countryname14




